package im.yisme.view.ui.util;

import android.graphics.PointF;

public class IsInQuadrangle {	      	  
	    /** 
	     * 判断p是否在abcd组成的四边形内 
	     * @param a 
	     * @param b 
	     * @param c 
	     * @param d 
	     * @param p 
	     * @return 如果p在四边形内返回true,否则返回false. 
	     */  
	    public static boolean pInQuadrangle(PointF a, PointF b, PointF c, PointF d,  
	            PointF p) {  
	        double dTriangle = triangleArea(a, b, p) + triangleArea(b, c, p)  
	                + triangleArea(c, d, p) + triangleArea(d, a, p);  
	        double dQuadrangle = triangleArea(a, b, c) + triangleArea(c, d, a);  
	        return dTriangle == dQuadrangle;  
	    }  
	  
	    // 返回三个点组成三角形的面积  
	    private static double triangleArea(PointF a, PointF b, PointF c) {  
	        double result = Math.abs((a.x * b.y + b.x * c.y + c.x * a.y - b.x * a.y  
	                - c.x * b.y - a.x * c.y) / 2.0D);  
	        return result;  
	    }  
	  

}
